package com.cjl.security.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjl.model.system.SysLoginLog;
import com.cjl.security.mapper.SysLoginLogMapper;
import com.cjl.security.service.SysLoginLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cjl.vo.system.SysLoginLogQueryVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 系统访问记录 服务实现类
 * </p>
 *
 * @author cjl
 * @since 2023-03-20
 */
@Service
public class SysLoginLogServiceImpl extends ServiceImpl<SysLoginLogMapper, SysLoginLog> implements SysLoginLogService {

    @Override
    public IPage<SysLoginLog> queryUser(SysLoginLogQueryVo sysLoginLogQueryVo, Page<SysLoginLog> pageParam) {
        LambdaQueryWrapper<SysLoginLog> wrapper = new LambdaQueryWrapper<>();
        String username = sysLoginLogQueryVo.getUsername();
        String createTimeBegin = sysLoginLogQueryVo.getCreateTimeBegin();
        String createTimeEnd = sysLoginLogQueryVo.getCreateTimeEnd();

        if(!StringUtils.isEmpty(username)){
            wrapper.like(SysLoginLog::getUsername, username);
        }
        if(!StringUtils.isEmpty(createTimeBegin)){
            wrapper.ge(SysLoginLog::getCreateTime, createTimeBegin);
        }
        if(!StringUtils.isEmpty(createTimeEnd)){
            wrapper.le(SysLoginLog::getCreateTime, createTimeEnd);
        }
        Page<SysLoginLog> sysLoginLogPage = baseMapper.selectPage(pageParam, wrapper);
        return sysLoginLogPage;
    }
}
